﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using AMicroblogAPI;
using AMicroblogAPI.DataContract;
using AMicroblogAPI.Common;

public partial class SignInSinaCallback : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var verifer = Request.QueryString["oauth_verifier"];

        var reqToken = Session["RequestToken"] as OAuthRequestToken;
        var accessToken = AMicroblogAPI.AMicroblog.GetAccessToken(reqToken, verifer);

        Session["AccessToken"] = accessToken;
        
        AMicroblogAPI.Environment.AccessToken = accessToken;
        var userInfo = AMicroblog.VerifyCredential();
        string name = userInfo.Name;

        var rnd = new Random();

        UpdateStatusInfo statusInfo = new UpdateStatusInfo();
        statusInfo.Status = "Hello, weibo" + rnd.Next().ToString();
        AMicroblog.PostStatus(statusInfo);
        Response.Redirect("Default.aspx");
    }
}